import { Component } from '@angular/core';
import { Router } from '@angular/router';
import * as Parse from "parse"
@Component({
  selector: 'app-page-login',
  templateUrl: './page-login.component.html',
  styleUrls: ['./page-login.component.scss']
})
export class PageLoginComponent {
  username: string = ""
  password: string = ""

  userdata: Parse.User | undefined
  constructor(private router: Router) {
    this.userdata = Parse.User.current();
  }
  login() {
    Parse.User.logIn(this.username, this.password).then(userdata => {
      this.userdata = userdata
      if (this.userdata?.id) {
        this.router.navigate(["/intelligent-shopping/home"])
      }
      else
      alert('账号或密码错误')
    })
  }
  logout() {
    Parse.User.logOut().then(data => {
      localStorage.clear();
    })
       this.router.navigate(["../intelligent-shopping/my"])
  }
  // goMy(){
  //   this.router.navigate(["../intelligent-shopping/my"])
  // }
  // constructor(private router:Router){}
  userList: any
  async ngOnInit(): Promise<void> {

    // 查询Student
    let query = new Parse.Query("users")
    //     query.equalTo("goodsID","006")
    //     query.limit(1)
    let list = await query.find()
    console.log(list + "user")
    this.userList = list
  }
}
